<template>
	<!-- 上传付款凭证 -->
	<view class="box">
		<u-form :model="form" ref="uForm">
				<u-form-item label="付款凭证" label-width="200">
					<u-upload :maxCount="maxCount" :showProgress="false"
						@on-uploaded="uploadSuccess" @on-remove="uploadRemove"
						:action="`${$BASE_URL}/api/common/upload`" :header="{token: token}"
						width="138" height="138">
					</u-upload>
				</u-form-item>
			</u-form>
			<button class="btn1" style="background-color: #03A9F4;" @click="submit()">提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				maxCount:1,
				token: uni.getStorageSync('token'),
				form:{
					work_id:'',
					ding_image:''
				},
				options:[]
			}
		},
		onLoad(options) {
			this.options = options;
		},
		methods: {
			//提交
			submit(){
				var _this = this;
				_this.form.work_id = _this.options.id;
				if(_this.form.ding_image == '' || !_this.form.ding_image){
					uni.showToast({
						title:'请上传图片',
						icon:'none'
					})
					return false;
				}
				_this.$http('apply.nh_uploadDing',_this.form).then(res=>{
					if(res.code == 1){
						uni.showToast({
							title:'提交成功',
							icon:'success',
							success(){
								uni.redirectTo({
									url:'/pages/index/xuqiu'
								})
							}
						})
					}else{
						uni.showToast({
							title:res.msg,
							icon:'error',
						})
					}
				})
			},
			// 上传图片成功
			uploadSuccess(e) {
				this.imgList = [];
				e.forEach(item => {
					this.form.ding_image= item.response.data.url;
				});
			},
			// 移除图片
			uploadRemove(index) {
				this.form.ding_image = '';
			},
			// 上传图片成功
			uploadSuccess2(e) {
				this.imgList = [];
				e.forEach(item => {
					this.form.ding_image= item.response.data.url;
				});
			},
		}
	}
</script>

<style>
	page{
		background-color: #fff;
	}
	.box{
		margin: 30rpx 30rpx;
		
	}
	.btn1{
		background-color: #388E3C;
		color: #fff;
	}
</style>
